package utility;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;

import dbmanager.DBManager;

public class UpdateData
{
	public static void UpdateData() 
	{
		DBManager dbRemote = new DBManager("org.postgresql.Driver","jdbc:postgresql:","//192.168.1.130/Oldretail","postgres","1");
		dbRemote.getConnect();
		
		DBManager dbClient = new DBManager();
		dbClient.getConnect();
		int count=0;
		ResultSet rs = dbRemote.getSelect("select * from property_details where mid=7352 order by mid,pid");
		try
		{
			while(rs.next())
			{
				String mid = rs.getString("mid");
				String pid = rs.getString("pid");
				String pv = rs.getString("pv");
				String vt = rs.getString("vt");
				String ref = rs.getString("ref");
				String fd = rs.getString("fd");
				
				//String query = "Update property_details set pv="+pv+",vt='"+vt+"' where mid="+mid+" and pid="+pid;
				Hashtable<Object, Object> table = new Hashtable<Object, Object>();
				table.put("mid", mid);
				table.put("pid", pid);
				table.put("pv", pv);
				table.put("vt", vt);
				table.put("ref", ref);
				table.put("fd", fd);
				//System.out.println(query);
				dbClient.getInsert("property_details",table);
				count++;
			}
			System.out.println(count);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public static void UpdateMasterData() 
	{
		DBManager dbRemote = new DBManager("org.postgresql.Driver","jdbc:postgresql:","//192.168.1.130/Oldretail","postgres","1");
		dbRemote.getConnect();
		
		DBManager dbClient = new DBManager();
		dbClient.getConnect();
		int count=0;
		ResultSet rs = dbRemote.getSelect("select * from master_table where id>11117 ");
		try
		{
			while(rs.next())
			{
				String id = rs.getString("id");
				String name = rs.getString("name");
				
				//String query = "Update property_details set pv="+pv+",vt='"+vt+"' where mid="+mid+" and pid="+pid;
				Hashtable<Object, Object> table = new Hashtable<Object, Object>();
				table.put("id", id);
				table.put("name", name);
				dbClient.getInsert("master_table",table);
				count++;
			}
			System.out.println(count);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		//new UpdateData();
		UpdateData.UpdateData(); 
	}
	

}
